#ifndef _WX_WINDOW_H_BASE_
#define _WX_WINDOW_H_BASE_

#include "wx/event.h"           // the base class
#include "wx/list.h"            // defines wxWindowList
#include "wx/cursor.h"          // we have member variables of these classes
#include "wx/font.h"            // so we can't do without them
#include "wx/colour.h"
#include "wx/region.h"
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/validate.h"        // for wxDefaultValidator (always include it)

#if wxUSE_PALETTE
#include "wx/palette.h"
#endif // wxUSE_PALETTE

#if wxUSE_ACCEL
#include "wx/accel.h"
#endif // wxUSE_ACCEL

// when building wxUniv/Foo we don't want the code for native menu use to be
// compiled in - it should only be used when building real wxFoo
#ifdef __WXUNIVERSAL__
#define wxUSE_MENUS_NATIVE 0
#else // !__WXUNIVERSAL__
#define wxUSE_MENUS_NATIVE wxUSE_MENUS
#endif // __WXUNIVERSAL__/!__WXUNIVERSAL__

class wxCaret;
class wxControl;
class wxCursor;
class wxDC;
class wxDropTarget;
class wxItemResource;
class wxLayoutConstraints;
class wxResourceTable;
class wxSizer;
class wxToolTip;
class wxWindowBase;
class wxWindow;
class wxScrollHelper;

struct wxVisualAttributes {
  wxFont font;
  wxColour colFg;
  wxColour colBg;
};

enum wxWindowVariant {
  wxWINDOW_VARIANT_NORMAL,  // Normal size
  wxWINDOW_VARIANT_SMALL,   // Smaller size (about 25 % smaller than normal)
  wxWINDOW_VARIANT_MINI,    // Mini size (about 33 % smaller than normal)
  wxWINDOW_VARIANT_LARGE,   // Large size (about 25 % larger than normal)
  wxWINDOW_VARIANT_MAX
};

#if wxUSE_SYSTEM_OPTIONS
#define wxWINDOW_DEFAULT_VARIANT wxT("window-default-variant")
#endif

WX_DECLARE_LIST_3( wxWindow, wxWindowBase, wxWindowList, wxWindowListNode);

extern wxWindowList wxTopLevelWindows;
extern wxList wxPendingDelete;

class wxWindowBase : public wxEvtHandler {
  public:
    wxWindowBase() ;
    bool CreateBase( wxWindowBase *parent,
                     wxWindowID winid,
                     const wxPoint& pos = wxDefaultPosition,
                     const wxSize& size = wxDefaultSize,
                     long style = 0,
                     const wxValidator& validator = wxDefaultValidator,
                     const wxString& name = wxPanelNameStr );

    virtual ~wxWindowBase();
    bool Close( bool force = false );
    virtual bool Destroy();
    bool DestroyChildren();
    bool IsBeingDeleted() const { return m_isBeingDeleted; }
    virtual void SetLabel( const wxString& label ) = 0;
    virtual wxString GetLabel() const = 0;
    virtual void SetName( const wxString &name ) { m_windowName = name; }
    virtual wxString GetName() const { return m_windowName; }
    void SetWindowVariant( wxWindowVariant variant );
    wxWindowVariant GetWindowVariant() const { return m_windowVariant; }
    void SetId( wxWindowID winid ) { m_windowId = winid; }
    wxWindowID GetId() const { return m_windowId; }
    virtual wxLayoutDirection GetLayoutDirection() const { return wxLayout_Default; }
    virtual void SetLayoutDirection( wxLayoutDirection( dir ) ) { }
    virtual wxCoord AdjustForLayoutDirection( wxCoord x, wxCoord width, wxCoord widthTotal ) const;
    static int NewControlId() { return --ms_lastControlId; }
    static int NextControlId( int winid ) { return winid - 1; }
    static int PrevControlId( int winid ) { return winid + 1; }
    void SetSize( int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO ) {
      DoSetSize( x, y, width, height, sizeFlags );
    }

    void SetSize( int width, int height ) {
      DoSetSize( wxDefaultCoord, wxDefaultCoord, width, height, wxSIZE_USE_EXISTING );
    }

    void SetSize( const wxSize& size ) { SetSize( size.x, size.y ); }

    void SetSize( const wxRect& rect, int sizeFlags = wxSIZE_AUTO ) {
      DoSetSize( rect.x, rect.y, rect.width, rect.height, sizeFlags );
    }

    void Move( int x, int y, int flags = wxSIZE_USE_EXISTING ) {
      DoSetSize( x, y, wxDefaultCoord, wxDefaultCoord, flags );
    }

    void Move( const wxPoint& pt, int flags = wxSIZE_USE_EXISTING ) { Move( pt.x, pt.y, flags ); }
    void SetPosition( const wxPoint& pt ) { Move( pt ); }
    virtual void Raise() = 0;
    virtual void Lower() = 0;
    void SetClientSize( int width, int height ) { DoSetClientSize( width, height ); }
    void SetClientSize( const wxSize& size ) { DoSetClientSize( size.x, size.y ); }
    void SetClientSize( const wxRect& rect ) { SetClientSize( rect.width, rect.height ); }
    void GetPosition( int *x, int *y ) const { DoGetPosition( x, y ); }
    wxPoint GetPosition() const {
      int x, y;
      DoGetPosition( &x, &y );
      return wxPoint( x, y );
    }

    void GetScreenPosition( int *x, int *y ) const { DoGetScreenPosition( x, y ); }
    wxPoint GetScreenPosition() const {
      int x, y;
      DoGetScreenPosition( &x, &y );
      return wxPoint( x, y );
    }

    void GetSize( int *w, int *h ) const { DoGetSize( w, h ); }
    wxSize GetSize() const {
      int w, h;
      DoGetSize( & w, & h );
      return wxSize( w, h );
    }

    void GetClientSize( int *w, int *h ) const { DoGetClientSize( w, h ); }
    wxSize GetClientSize() const {
      int w, h;
      DoGetClientSize( &w, &h );
      return wxSize( w, h );
    }

    wxRect GetRect() const {
      int x, y, w, h;
      GetPosition( &x, &y );
      GetSize( &w, &h );
      return wxRect( x, y, w, h );
    }

    wxRect GetScreenRect() const {
      int x, y, w, h;
      GetScreenPosition( &x, &y );
      GetSize( &w, &h );
      return wxRect( x, y, w, h );
    }
    virtual wxPoint GetClientAreaOrigin() const;
    wxRect GetClientRect() const {
      return wxRect( GetClientAreaOrigin(), GetClientSize() );
    }

    wxSize ClientToWindowSize( const wxSize& size ) const;
    wxSize WindowToClientSize( const wxSize& size ) const;
    wxSize GetBestSize() const {
      if( m_bestSizeCache.IsFullySpecified() ) {
        return m_bestSizeCache;
      }
      return DoGetBestSize();
    }
    void GetBestSize( int *w, int *h ) const {
      wxSize s = GetBestSize();
      if( w ) {
        *w = s.x;
      }
      if( h ) {
        *h = s.y;
      }
    }

    void SetScrollHelper( wxScrollHelper *sh ) { m_scrollHelper = sh; }
    wxScrollHelper *GetScrollHelper() { return m_scrollHelper; }
    void InvalidateBestSize();
    void CacheBestSize( const wxSize& size ) const {
      wxConstCast( this, wxWindowBase )->m_bestSizeCache = size;
    }
    wxSize GetEffectiveMinSize() const;
    wxDEPRECATED( wxSize GetBestFittingSize() const );  // replaced by GetEffectiveMinSize
    wxDEPRECATED( wxSize GetAdjustedMinSize() const );  // replaced by GetEffectiveMinSize
    void SetInitialSize( const wxSize& size = wxDefaultSize );
    wxDEPRECATED( void SetBestFittingSize( const wxSize& size = wxDefaultSize ) ); // replaced by SetInitialSize
    void Centre( int dir = wxBOTH ) { DoCentre( dir ); }
    void Center( int dir = wxBOTH ) { DoCentre( dir ); }
    void CentreOnParent( int dir = wxBOTH ) { DoCentre( dir ); }
    void CenterOnParent( int dir = wxBOTH ) { CentreOnParent( dir ); }
    virtual void Fit();
    virtual void FitInside();
    virtual void SetSizeHints( int minW, int minH, int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
                               int incW = wxDefaultCoord, int incH = wxDefaultCoord ) {
      DoSetSizeHints( minW, minH, maxW, maxH, incW, incH );
    }

    void SetSizeHints( const wxSize& minSize, const wxSize& maxSize = wxDefaultSize, const wxSize& incSize = wxDefaultSize ) {
      DoSetSizeHints( minSize.x, minSize.y, maxSize.x, maxSize.y, incSize.x, incSize.y );
    }

    virtual void DoSetSizeHints( int minW, int minH, int maxW, int maxH, int incW, int incH );
    virtual void SetVirtualSizeHints( int minW, int minH, int maxW = wxDefaultCoord, int maxH = wxDefaultCoord );
    void SetVirtualSizeHints( const wxSize& minSize, const wxSize& maxSize = wxDefaultSize ) {
      SetVirtualSizeHints( minSize.x, minSize.y, maxSize.x, maxSize.y );
    }


    virtual void SetMinSize( const wxSize& minSize ) { m_minWidth = minSize.x; m_minHeight = minSize.y; }
    virtual void SetMaxSize( const wxSize& maxSize ) { m_maxWidth = maxSize.x; m_maxHeight = maxSize.y; }
    virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); }
    virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); }
    int GetMinWidth() const { return GetMinSize().x; }
    int GetMinHeight() const { return GetMinSize().y; }
    int GetMaxWidth() const { return GetMaxSize().x; }
    int GetMaxHeight() const { return GetMaxSize().y; }
    void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); }
    void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); }

    wxSize GetVirtualSize() const { return DoGetVirtualSize(); }
    void GetVirtualSize( int *x, int *y ) const {
      wxSize s( DoGetVirtualSize() );
      if( x ) {
        *x = s.GetWidth();
      }
      if( y ) {
        *y = s.GetHeight();
      }
    }

    virtual void DoSetVirtualSize( int x, int y );
    virtual wxSize DoGetVirtualSize() const;
    virtual wxSize GetBestVirtualSize() const {
      wxSize  client( GetClientSize() );
      wxSize  best( GetBestSize() );
      return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) );
    }
    virtual wxSize GetWindowBorderSize() const;
    virtual bool Show( bool show = true );
    bool Hide() { return Show( false ); }
    virtual bool Enable( bool enable = true );
    bool Disable() { return Enable( false ); }
    virtual bool IsShown() const { return m_isShown; }
    virtual bool IsEnabled() const { return m_isEnabled; }
    virtual bool IsShownOnScreen() const;
    virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
    virtual long GetWindowStyleFlag() const { return m_windowStyle; }
    void SetWindowStyle( long style ) { SetWindowStyleFlag( style ); }
    long GetWindowStyle() const { return GetWindowStyleFlag(); }
    bool HasFlag( int flag ) const { return ( m_windowStyle & flag ) != 0; }
    virtual bool IsRetained() const { return HasFlag( wxRETAINED ); }
    bool ToggleWindowStyle( int flag );
    virtual void SetExtraStyle( long exStyle ) { m_exStyle = exStyle; }
    long GetExtraStyle() const { return m_exStyle; }
    virtual void MakeModal( bool modal = true );
    virtual void SetThemeEnabled( bool enableTheme ) { m_themeEnabled = enableTheme; }
    virtual bool GetThemeEnabled() const { return m_themeEnabled; }
    virtual void SetFocus() = 0;
    virtual void SetFocusFromKbd() { SetFocus(); }
    static wxWindow *FindFocus();
    static wxWindow *DoFindFocus() /* = 0: implement in derived classes */;
    virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
    virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
    virtual bool Navigate( int flags = wxNavigationKeyEvent::IsForward );
    void MoveBeforeInTabOrder( wxWindow *win ) { DoMoveInTabOrder( win, MoveBefore ); }
    void MoveAfterInTabOrder( wxWindow *win ) { DoMoveInTabOrder( win, MoveAfter ); }
    const wxWindowList& GetChildren() const { return m_children; }
    wxWindowList& GetChildren() { return m_children; }
    const wxWindowList& GetWindowChildren() const { return GetChildren() ; }
    wxWindow *GetPrevSibling() const { return DoGetSibling( MoveBefore ); }
    wxWindow *GetNextSibling() const { return DoGetSibling( MoveAfter ); }
    wxWindow *GetParent() const { return m_parent; }
    inline wxWindow *GetGrandParent() const;
    virtual bool IsTopLevel() const;
    void SetParent( wxWindowBase *parent ) { m_parent = ( wxWindow * )parent; }
    virtual bool Reparent( wxWindowBase *newParent );
    virtual void AddChild( wxWindowBase *child );
    virtual void RemoveChild( wxWindowBase *child );
    wxWindow *FindWindow( long winid ) const;
    wxWindow *FindWindow( const wxString& name ) const;
    static wxWindow *FindWindowById( long winid, const wxWindow *parent = NULL );
    static wxWindow *FindWindowByName( const wxString& name, const wxWindow *parent = NULL );
    static wxWindow *FindWindowByLabel( const wxString& label, const wxWindow *parent = NULL );
    wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
    void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
    void PushEventHandler( wxEvtHandler *handler );
    wxEvtHandler *PopEventHandler( bool deleteHandler = false );
    bool RemoveEventHandler( wxEvtHandler *handler );

    #if wxUSE_VALIDATORS
    // a window may have an associated validator which is used to control
    // user input
    virtual void SetValidator( const wxValidator &validator );
    virtual wxValidator *GetValidator() { return m_windowValidator; }
    #endif // wxUSE_VALIDATORS

    virtual bool Validate();
    virtual bool TransferDataToWindow();
    virtual bool TransferDataFromWindow();
    virtual void InitDialog();

    #if wxUSE_ACCEL
    virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ) { m_acceleratorTable = accel; }
    wxAcceleratorTable *GetAcceleratorTable() { return &m_acceleratorTable; }

    #endif // wxUSE_ACCEL

    virtual bool RegisterHotKey( int hotkeyId, int modifiers, int keycode );
    virtual bool UnregisterHotKey( int hotkeyId );

    wxPoint ConvertPixelsToDialog( const wxPoint& pt );
    wxPoint ConvertDialogToPixels( const wxPoint& pt );
    wxSize ConvertPixelsToDialog( const wxSize& sz ) {
      wxPoint pt( ConvertPixelsToDialog( wxPoint( sz.x, sz.y ) ) );
      return wxSize( pt.x, pt.y );
    }

    wxSize ConvertDialogToPixels( const wxSize& sz ) {
      wxPoint pt( ConvertDialogToPixels( wxPoint( sz.x, sz.y ) ) );
      return wxSize( pt.x, pt.y );
    }

    virtual void WarpPointer( int x, int y ) = 0;
    void CaptureMouse();
    void ReleaseMouse();
    static wxWindow *GetCapture();
    virtual bool HasCapture() const { return ( wxWindow * )this == GetCapture(); }
    virtual void Refresh( bool eraseBackground = true, const wxRect *rect = ( const wxRect * ) NULL ) = 0;
    void RefreshRect( const wxRect& rect, bool eraseBackground = true ) {
      Refresh( eraseBackground, &rect );
    }

    virtual void Update() { }
    virtual void ClearBackground();
    virtual void Freeze() { }
    virtual void Thaw() { }
    virtual bool IsFrozen() const { return false; }
    virtual void PrepareDC( wxDC & ( dc ) ) { }
    virtual bool IsDoubleBuffered() const { return false; }
    const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
    wxRegion& GetUpdateRegion() { return m_updateRegion; }
    wxRect GetUpdateClientRect() const;
    virtual bool DoIsExposed( int x, int y ) const;
    virtual bool DoIsExposed( int x, int y, int w, int h ) const;
    bool IsExposed( int x, int y ) const { return DoIsExposed( x, y ); }
    bool IsExposed( int x, int y, int w, int h ) const { return DoIsExposed( x, y, w, h ); }
    bool IsExposed( const wxPoint& pt ) const { return DoIsExposed( pt.x, pt.y ); }
    bool IsExposed( const wxRect& rect ) const { return DoIsExposed( rect.x, rect.y, rect.width, rect.height ); }
    virtual wxVisualAttributes GetDefaultAttributes() const {
      return GetClassDefaultAttributes( GetWindowVariant() );
    }

    static wxVisualAttributes
    GetClassDefaultAttributes( wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL );
    virtual bool SetBackgroundColour( const wxColour& colour );
    void SetOwnBackgroundColour( const wxColour& colour ) {
      if( SetBackgroundColour( colour ) ) {
        m_inheritBgCol = false;
      }
    }
    wxColour GetBackgroundColour() const;
    bool InheritsBackgroundColour() const {
      return m_inheritBgCol;
    }
    bool UseBgCol() const {
      return m_hasBgCol;
    }

    virtual bool SetForegroundColour( const wxColour& colour );
    void SetOwnForegroundColour( const wxColour& colour ) {
      if( SetForegroundColour( colour ) ) {
        m_inheritFgCol = false;
      }
    }
    wxColour GetForegroundColour() const;
    virtual bool SetBackgroundStyle( wxBackgroundStyle style ) { m_backgroundStyle = style; return true; }
    virtual wxBackgroundStyle GetBackgroundStyle() const { return m_backgroundStyle; }
    virtual bool HasTransparentBackground() { return false; }
    virtual bool SetFont( const wxFont& font ) = 0;
    void SetOwnFont( const wxFont& font ) {
      if( SetFont( font ) ) {
        m_inheritFont = false;
      }
    }
    wxFont GetFont() const;

    // set/retrieve the cursor for this window (SetCursor() returns true
    // if the cursor was really changed)
    virtual bool SetCursor( const wxCursor &cursor );
    const wxCursor& GetCursor() const { return m_cursor; }

    #if wxUSE_CARET
    // associate a caret with the window
    void SetCaret( wxCaret *caret );
    // get the current caret (may be NULL)
    wxCaret *GetCaret() const { return m_caret; }
    #endif // wxUSE_CARET

    // get the (average) character size for the current font
    virtual int GetCharHeight() const = 0;
    virtual int GetCharWidth() const = 0;
    virtual void GetTextExtent( const wxString& string, int *x, int *y, int *descent = ( int * ) NULL,
                                int *externalLeading = ( int * ) NULL, const wxFont *theFont = ( const wxFont * ) NULL )
    const = 0;

    void ClientToScreen( int *x, int *y ) const { DoClientToScreen( x, y ); }
    void ScreenToClient( int *x, int *y ) const { DoScreenToClient( x, y ); }
    wxPoint ClientToScreen( const wxPoint& pt ) const {
      int x = pt.x, y = pt.y;
      DoClientToScreen( &x, &y );
      return wxPoint( x, y );
    }

    wxPoint ScreenToClient( const wxPoint& pt ) const {
      int x = pt.x, y = pt.y;
      DoScreenToClient( &x, &y );
      return wxPoint( x, y );
    }

    wxHitTest HitTest( wxCoord x, wxCoord y ) const { return DoHitTest( x, y ); }
    wxHitTest HitTest( const wxPoint& pt ) const { return DoHitTest( pt.x, pt.y ); }
    wxBorder GetBorder( long flags ) const;
    wxBorder GetBorder() const { return GetBorder( GetWindowStyleFlag() ); }
    virtual void UpdateWindowUI( long flags = wxUPDATE_UI_NONE );
    virtual void DoUpdateWindowUI( wxUpdateUIEvent& event ) ;
    bool PopupMenu( wxMenu *menu, const wxPoint& pos = wxDefaultPosition ) { return DoPopupMenu( menu, pos.x, pos.y ); }
    bool PopupMenu( wxMenu *menu, int x, int y ) { return DoPopupMenu( menu, x, y ); }
    virtual bool HasMultiplePages() const { return false; }
    bool HasScrollbar( int orient ) const {
      return ( m_windowStyle &
               ( orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL ) ) != 0;
    }

    virtual void SetScrollbar( int orient, int pos, int thumbvisible, int range, bool refresh = true ) = 0;
    virtual void SetScrollPos( int orient, int pos, bool refresh = true ) = 0;
    virtual int GetScrollPos( int orient ) const = 0;
    virtual int GetScrollThumb( int orient ) const = 0;
    virtual int GetScrollRange( int orient ) const = 0;
    virtual void ScrollWindow( int dx, int dy, const wxRect* rect = ( wxRect * ) NULL ) = 0;
    virtual bool ScrollLines( int ( lines ) ) { return false; }
    virtual bool ScrollPages( int ( pages ) ) { return false; }
    bool LineUp() { return ScrollLines( -1 ); }
    bool LineDown() { return ScrollLines( 1 ); }
    bool PageUp() { return ScrollPages( -1 ); }
    bool PageDown() { return ScrollPages( 1 ); }
    void SetHelpText( const wxString& text );
    void SetHelpTextForId( const wxString& text );
    virtual wxString GetHelpTextAtPoint( const wxPoint& pt,wxHelpEvent::Origin origin ) const;
    wxString GetHelpText() const {
      return GetHelpTextAtPoint( wxDefaultPosition, wxHelpEvent::Origin_Unknown );
    }

    #if wxUSE_TOOLTIPS
    // the easiest way to set a tooltip for a window is to use this method
    void SetToolTip( const wxString &tip );
    // attach a tooltip to the window
    void SetToolTip( wxToolTip *tip ) { DoSetToolTip( tip ); }
    // more readable synonym for SetToolTip(NULL)
    void UnsetToolTip() { SetToolTip( NULL ); }
    // get the associated tooltip or NULL if none
    wxToolTip* GetToolTip() const { return m_tooltip; }
    wxString GetToolTipText() const ;
    #else // !wxUSE_TOOLTIPS
    // make it much easier to compile apps in an environment
    // that doesn't support tooltips, such as PocketPC
    void SetToolTip( const wxString & ( tip ) ) {}
    void UnsetToolTip() { }
    #endif // wxUSE_TOOLTIPS/!wxUSE_TOOLTIPS

    // drag and drop
    // -------------
    #if wxUSE_DRAG_AND_DROP
    virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
    virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
    void DragAcceptFiles( bool accept );
    #endif // wxUSE_DRAG_AND_DROP
    #if wxUSE_CONSTRAINTS
    void SetConstraints( wxLayoutConstraints *constraints );
    wxLayoutConstraints *GetConstraints() const { return m_constraints; }
    void UnsetConstraints( wxLayoutConstraints *c );
    wxWindowList *GetConstraintsInvolvedIn() const { return m_constraintsInvolvedIn; }
    void AddConstraintReference( wxWindowBase *otherWin );
    void RemoveConstraintReference( wxWindowBase *otherWin );
    void DeleteRelatedConstraints();
    void ResetConstraints();

    // these methods may be overridden for special layout algorithms
    virtual void SetConstraintSizes( bool recurse = true );
    virtual bool LayoutPhase1( int *noChanges );
    virtual bool LayoutPhase2( int *noChanges );
    virtual bool DoPhase( int phase );

    // these methods are virtual but normally won't be overridden
    virtual void SetSizeConstraint( int x, int y, int w, int h );
    virtual void MoveConstraint( int x, int y );
    virtual void GetSizeConstraint( int *w, int *h ) const ;
    virtual void GetClientSizeConstraint( int *w, int *h ) const ;
    virtual void GetPositionConstraint( int *x, int *y ) const ;

    #endif // wxUSE_CONSTRAINTS
    void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
    bool GetAutoLayout() const { return m_autoLayout; }
    virtual bool Layout();
    void SetSizer( wxSizer *sizer, bool deleteOld = true );
    void SetSizerAndFit( wxSizer *sizer, bool deleteOld = true );
    wxSizer *GetSizer() const { return m_windowSizer; }
    void SetContainingSizer( wxSizer* sizer );
    wxSizer *GetContainingSizer() const { return m_containingSizer; }
    virtual bool SetTransparent( wxByte( alpha ) ) { return false; }
    virtual bool CanSetTransparent() { return false; }
    void OnSysColourChanged( wxSysColourChangedEvent& event );
    void OnInitDialog( wxInitDialogEvent &event );
    void OnMiddleClick( wxMouseEvent& event );
    void OnHelp( wxHelpEvent& event );
    virtual void OnInternalIdle() {}
    virtual WXWidget GetHandle() const = 0;
    virtual void AssociateHandle( WXWidget  handle ) { }
    virtual void DissociateHandle() { }

    #if wxUSE_PALETTE
    wxPalette GetPalette() const { return m_palette; }
    void SetPalette( const wxPalette& pal );
    bool HasCustomPalette() const { return m_hasCustomPalette; }
    wxWindow *GetAncestorWithCustomPalette() const;
    #endif // wxUSE_PALETTE

    virtual void InheritAttributes();
    virtual bool ShouldInheritColours() const { return false; }
  protected:
    virtual bool TryValidator( wxEvent& event );
    virtual bool TryParent( wxEvent& event );
    enum MoveKind {
      MoveBefore,     // insert before the given window
      MoveAfter       // insert after the given window
    };

    wxWindow *DoGetSibling( MoveKind order ) const;
    virtual void DoMoveInTabOrder( wxWindow *win, MoveKind move );

    #if wxUSE_CONSTRAINTS
    void SatisfyConstraints();
    #endif // wxUSE_CONSTRAINTS
    void SendDestroyEvent();
    virtual wxWindow *GetMainWindowOfCompositeControl() { return ( wxWindow* )this; }
    wxWindowID m_windowId;
    wxWindow *m_parent;
    wxWindowList m_children;
    int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
    wxEvtHandler        *m_eventHandler;

    #if wxUSE_VALIDATORS
    wxValidator         *m_windowValidator;
    #endif // wxUSE_VALIDATORS

    #if wxUSE_DRAG_AND_DROP
    wxDropTarget        *m_dropTarget;
    #endif // wxUSE_DRAG_AND_DROP

    // visual window attributes
    wxCursor             m_cursor;
    wxFont               m_font;                // see m_hasFont
    wxColour             m_backgroundColour,    //     m_hasBgCol
                         m_foregroundColour;    //     m_hasFgCol

    #if wxUSE_CARET
    wxCaret             *m_caret;
    #endif // wxUSE_CARET
    wxRegion             m_updateRegion;

    #if wxUSE_ACCEL
    wxAcceleratorTable   m_acceleratorTable;
    #endif // wxUSE_ACCEL

    #if wxUSE_TOOLTIPS
    wxToolTip           *m_tooltip;
    #endif // wxUSE_TOOLTIPS

    #if wxUSE_CONSTRAINTS
    wxLayoutConstraints *m_constraints;
    wxWindowList        *m_constraintsInvolvedIn;
    #endif // wxUSE_CONSTRAINTS

    // this window's sizer
    wxSizer             *m_windowSizer;

    // The sizer this window is a member of, if any
    wxSizer             *m_containingSizer;
    bool                 m_autoLayout: 1;
    bool                 m_isShown: 1;
    bool                 m_isEnabled: 1;
    bool                 m_isBeingDeleted: 1;
    bool                 m_hasBgCol: 1;
    bool                 m_hasFgCol: 1;
    bool                 m_hasFont: 1;
    bool                 m_inheritBgCol: 1;
    bool                 m_inheritFgCol: 1;
    bool                 m_inheritFont: 1;
    long                 m_windowStyle, m_exStyle;
    wxString             m_windowName;
    bool                 m_themeEnabled;
    wxBackgroundStyle    m_backgroundStyle;
    #if wxUSE_PALETTE
    wxPalette            m_palette;
    bool                 m_hasCustomPalette;
    #endif // wxUSE_PALETTE
    wxSize                m_virtualSize;
    wxScrollHelper       *m_scrollHelper;
    int                   m_minVirtualWidth;    // VirtualSizeHints
    int                   m_minVirtualHeight;
    int                   m_maxVirtualWidth;
    int                   m_maxVirtualHeight;
    wxWindowVariant       m_windowVariant ;
    virtual wxBorder GetDefaultBorder() const;
    static int WidthDefault( int w ) { return w == wxDefaultCoord ? 20 : w; }
    static int HeightDefault( int h ) { return h == wxDefaultCoord ? 20 : h; }
    wxSize m_bestSizeCache;
    wxDEPRECATED( void SetBestSize( const wxSize& size ) ); // use SetInitialSize
    wxDEPRECATED( virtual void SetInitialBestSize( const wxSize& size ) ); // use SetInitialSize
    virtual void DoClientToScreen( int *x, int *y ) const = 0;
    virtual void DoScreenToClient( int *x, int *y ) const = 0;
    virtual wxHitTest DoHitTest( wxCoord x, wxCoord y ) const;
    virtual void DoCaptureMouse() = 0;
    virtual void DoReleaseMouse() = 0;
    virtual void DoGetPosition( int *x, int *y ) const = 0;
    virtual void DoGetScreenPosition( int *x, int *y ) const;
    virtual void DoGetSize( int *width, int *height ) const = 0;
    virtual void DoGetClientSize( int *width, int *height ) const = 0;
    virtual wxSize DoGetBestSize() const;
    virtual wxSize GetWindowSizeForVirtualSize( const wxSize& size ) const {
      return size;
    }
    virtual void DoSetSize( int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO ) = 0;
    virtual void DoSetClientSize( int width, int height ) = 0;
    virtual void DoMoveWindow( int x, int y, int width, int height ) = 0;
    virtual void DoCentre( int dir );

    #if wxUSE_TOOLTIPS
    virtual void DoSetToolTip( wxToolTip *tip );
    #endif // wxUSE_TOOLTIPS

    virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
    virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags = 0 ) const;
    virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
    static void NotifyCaptureLost();
  private:
    static int ms_lastControlId;
    static struct wxWindowNext *ms_winCaptureNext;
    static wxWindow *ms_winCaptureCurrent;
    static bool ms_winCaptureChanging;
    DECLARE_ABSTRACT_CLASS( wxWindowBase )
    DECLARE_NO_COPY_CLASS( wxWindowBase )
    DECLARE_EVENT_TABLE()
};

inline wxSize wxWindowBase::GetBestFittingSize() const {
  return GetEffectiveMinSize();
}

inline void wxWindowBase::SetBestFittingSize( const wxSize& size ) {
  SetInitialSize( size );
}

inline void wxWindowBase::SetBestSize( const wxSize& size ) {
  SetInitialSize( size );
}

inline void wxWindowBase::SetInitialBestSize( const wxSize& size ) {
  SetInitialSize( size );
}

#include "wx/gtk/window.h"

#if defined(__WXUNIVERSAL__)
#ifndef wxWindowNative
#error "wxWindowNative must be defined above!"
#endif

#include "wx/univ/window.h"
#endif // wxUniv

inline wxWindow *wxWindowBase::GetGrandParent() const {
  return m_parent ? m_parent->GetParent() : ( wxWindow * )NULL;
}

extern wxWindow* wxFindWindowAtPointer( wxPoint& pt );
extern wxPoint wxGetMousePosition();
extern wxWindow *wxGetActiveWindow();
wxWindow* wxGetTopLevelParent( wxWindow *win );
wxDEPRECATED( int NewControlId() );
inline int NewControlId() { return wxWindowBase::NewControlId(); }

#endif
